#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sysdef changeFilename(dir): file_directories = os.listdir(dir) currentpath = os.getcwd() os.chdir(dir) # 列出目录 print("目录为: %s"%dir) file_init = "fire" count = 0 for filename in file_directories: file_count = "%04d" % count filename_ext = filename.split(".") filename_new = "{0}_{1}.{2}".format(file_init,file_count,filename_ext[1]) # 重命名 os.rename(filename,filename_new) count = 1 print("重命名成功。") # 列出重命名后的目录 print("目录为: %s" %os.listdir(os.getcwd())) os.chdir(currentpath)if __name__ == "__main__": filedir = "D:/DeepLearning/learndata/fires/" changeFilename(filedir)
评论